home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / templates.jar / symantec / itools / wizards / JFCFrame / JFrame1.java < prev   
Text File  |  1998-11-02  |  18KB  |  496 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import com.sun.java.swing.*;
  5.  
  6. import com.symantec.itools.swing.JToolBarSeparator;
  7. import com.symantec.itools.swing.icons.ImageIcon;
  8.  
  9. /**
  10.  * A basic JFC based application.
  11.  */
  12. public class JFrame1 extends com.sun.java.swing.JFrame
  13. {
  14.     public JFrame1()
  15.     {
  16.         // This code is automatically generated by Visual Cafe when you add
  17.         // components to the visual environment. It instantiates and initializes
  18.         // the components. To modify the code, only use code syntax that matches
  19.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  20.         // parse your Java file into its visual environment.
  21.         //{{INIT_CONTROLS
  22.         setJMenuBar(JMenuBar1);
  23.         setTitle("JFC Application");
  24.         setDefaultCloseOperation(com.sun.java.swing.JFrame.DO_NOTHING_ON_CLOSE);
  25.         getContentPane().setLayout(new BorderLayout(0,0));
  26.         setSize(488,309);
  27.         setVisible(false);
  28.         try {
  29.             newIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/new.gif"));
  30.         }
  31.         catch (java.net.MalformedURLException error) { }
  32.         //$$ newIcon.move(144,312);
  33.         try {
  34.             openIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/open.gif"));
  35.         }
  36.         catch (java.net.MalformedURLException error) { }
  37.         //$$ openIcon.move(120,312);
  38.         try {
  39.             saveIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/save.gif"));
  40.         }
  41.         catch (java.net.MalformedURLException error) { }
  42.         //$$ saveIcon.move(96,312);
  43.         try {
  44.             cutIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/cut.gif"));
  45.         }
  46.         catch (java.net.MalformedURLException error) { }
  47.         //$$ cutIcon.move(72,312);
  48.         try {
  49.             copyIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/copy.gif"));
  50.         }
  51.         catch (java.net.MalformedURLException error) { }
  52.         //$$ copyIcon.move(48,312);
  53.         try {
  54.             pasteIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/paste.gif"));
  55.         }
  56.         catch (java.net.MalformedURLException error) { }
  57.         //$$ pasteIcon.move(24,312);
  58.         try {
  59.             aboutIcon.setImageLocation(symantec.itools.net.RelativeURL.getURL("images/about.gif"));
  60.         }
  61.         catch (java.net.MalformedURLException error) { }
  62.         //$$ aboutIcon.move(0,312);
  63.         saveFileDialog.setMode(FileDialog.SAVE);
  64.         saveFileDialog.setTitle("Save");
  65.         //$$ saveFileDialog.move(24,336);
  66.         openFileDialog.setMode(FileDialog.LOAD);
  67.         openFileDialog.setTitle("Open");
  68.         //$$ openFileDialog.move(0,336);
  69.         JPanel2.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
  70.         getContentPane().add("North", JPanel2);
  71.         JPanel2.setBounds(0,0,488,29);
  72.         JToolBar1.setAlignmentY(0.222222F);
  73.         JPanel2.add(JToolBar1);
  74.         JToolBar1.setBounds(0,0,199,29);
  75.         newButton.setIcon(newIcon);
  76.         newButton.setToolTipText("Create a new document");
  77.         newButton.setMnemonic((int)'N');
  78.         JToolBar1.add(newButton);
  79.         newButton.setBounds(16,4,23,23);
  80.         openButton.setIcon(openIcon);
  81.         openButton.setToolTipText("Open an existing document");
  82.         openButton.setMnemonic((int)'O');
  83.         JToolBar1.add(openButton);
  84.         openButton.setBounds(39,4,23,23);
  85.         saveButton.setIcon(saveIcon);
  86.         saveButton.setToolTipText("Save the active document");
  87.         saveButton.setMnemonic((int)'S');
  88.         JToolBar1.add(saveButton);
  89.         saveButton.setBounds(62,4,23,23);
  90.         JToolBar1.add(JToolBarSeparator1);
  91.         JToolBarSeparator1.setBounds(85,2,10,5);
  92.         cutButton.setIcon(cutIcon);
  93.         cutButton.setToolTipText("Cut the selection and put it on the Clipboard");
  94.         cutButton.setMnemonic((int)'T');
  95.         JToolBar1.add(cutButton);
  96.         cutButton.setBounds(95,4,23,23);
  97.         copyButton.setIcon(copyIcon);
  98.         copyButton.setToolTipText("Copy the selection and put it on the Clipboard");
  99.         copyButton.setMnemonic((int)'C');
  100.         JToolBar1.add(copyButton);
  101.         copyButton.setBounds(118,4,23,23);
  102.         pasteButton.setIcon(pasteIcon);
  103.         pasteButton.setToolTipText("Insert Clipboard contents");
  104.         pasteButton.setMnemonic((int)'P');
  105.         JToolBar1.add(pasteButton);
  106.         pasteButton.setBounds(141,4,23,23);
  107.         JToolBar1.add(JToolBarSeparator2);
  108.         JToolBarSeparator2.setBounds(164,2,10,5);
  109.         aboutButton.setIcon(aboutIcon);
  110.         aboutButton.setToolTipText("Display program information, version number and copyright");
  111.         aboutButton.setMnemonic((int)'A');
  112.         JToolBar1.add(aboutButton);
  113.         aboutButton.setBounds(174,4,23,23);
  114.         JPanel1.setLayout(null);
  115.         getContentPane().add("Center", JPanel1);
  116.         JPanel1.setBounds(0,29,488,280);
  117.         //$$ JMenuBar1.move(168,312);
  118.         fileMenu.setText("File");
  119.         fileMenu.setActionCommand("File");
  120.         fileMenu.setMnemonic((int)'F');
  121.         JMenuBar1.add(fileMenu);
  122.         newItem.setIcon(newIcon);
  123.         newItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  124.         newItem.setText("New");
  125.         newItem.setActionCommand("New");
  126.         newItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, Event.CTRL_MASK));
  127.         newItem.setMnemonic((int)'N');
  128.         fileMenu.add(newItem);
  129.         openItem.setIcon(openIcon);
  130.         openItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  131.         openItem.setText("Open...");
  132.         openItem.setActionCommand("Open...");
  133.         openItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, Event.CTRL_MASK));
  134.         openItem.setMnemonic((int)'O');
  135.         fileMenu.add(openItem);
  136.         saveItem.setIcon(saveIcon);
  137.         saveItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  138.         saveItem.setText("Save");
  139.         saveItem.setActionCommand("Save");
  140.         saveItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, Event.CTRL_MASK));
  141.         saveItem.setMnemonic((int)'S');
  142.         fileMenu.add(saveItem);
  143.         saveAsItem.setText("Save As...");
  144.         saveAsItem.setActionCommand("Save As...");
  145.         saveAsItem.setMnemonic((int)'A');
  146.         fileMenu.add(saveAsItem);
  147.         fileMenu.add(JSeparator1);
  148.         exitItem.setText("Exit");
  149.         exitItem.setActionCommand("Exit");
  150.         exitItem.setMnemonic((int)'X');
  151.         fileMenu.add(exitItem);
  152.         editMenu.setText("Edit");
  153.         editMenu.setActionCommand("Edit");
  154.         editMenu.setMnemonic((int)'E');
  155.         JMenuBar1.add(editMenu);
  156.         cutItem.setIcon(cutIcon);
  157.         cutItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  158.         cutItem.setText("Cut");
  159.         cutItem.setActionCommand("Cut");
  160.         cutItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, Event.CTRL_MASK));
  161.         cutItem.setMnemonic((int)'T');
  162.         editMenu.add(cutItem);
  163.         copyItem.setIcon(copyIcon);
  164.         copyItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  165.         copyItem.setText("Copy");
  166.         copyItem.setActionCommand("Copy");
  167.         copyItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, Event.CTRL_MASK));
  168.         copyItem.setMnemonic((int)'C');
  169.         editMenu.add(copyItem);
  170.         pasteItem.setIcon(pasteIcon);
  171.         pasteItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  172.         pasteItem.setText("Paste");
  173.         pasteItem.setActionCommand("Paste");
  174.         pasteItem.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, Event.CTRL_MASK));
  175.         pasteItem.setMnemonic((int)'P');
  176.         editMenu.add(pasteItem);
  177.         helpMenu.setText("Help");
  178.         helpMenu.setActionCommand("Help");
  179.         helpMenu.setMnemonic((int)'H');
  180.         JMenuBar1.add(helpMenu);
  181.         aboutItem.setIcon(aboutIcon);
  182.         aboutItem.setHorizontalTextPosition(com.sun.java.swing.SwingConstants.RIGHT);
  183.         aboutItem.setText("About...");
  184.         aboutItem.setActionCommand("About...");
  185.         aboutItem.setMnemonic((int)'A');
  186.         helpMenu.add(aboutItem);
  187.         //}}
  188.  
  189.         //{{INIT_MENUS
  190.         //}}
  191.  
  192.         //{{REGISTER_LISTENERS
  193.         SymWindow aSymWindow = new SymWindow();
  194.         this.addWindowListener(aSymWindow);
  195.         SymAction lSymAction = new SymAction();
  196.         openItem.addActionListener(lSymAction);
  197.         saveItem.addActionListener(lSymAction);
  198.         exitItem.addActionListener(lSymAction);
  199.         aboutItem.addActionListener(lSymAction);
  200.         openButton.addActionListener(lSymAction);
  201.         saveButton.addActionListener(lSymAction);
  202.         aboutButton.addActionListener(lSymAction);
  203.         //}}
  204.     }
  205.  
  206.     /**
  207.      * Creates a new instance of JFrame1 with the given title.
  208.      * @param sTitle the title for the new frame.
  209.      * @see #JFrame1()
  210.      */
  211.     public JFrame1(String sTitle)
  212.     {
  213.         this();
  214.         setTitle(sTitle);
  215.     }
  216.     
  217.     /**
  218.      * The entry point for this application.
  219.      * Sets the Look and Feel to the System Look and Feel.
  220.      * Creates a new JFrame1 and makes it visible.
  221.      */
  222.     static public void main(String args[])
  223.     {
  224.         try {
  225.             // Add the following code if you want the Look and Feel
  226.             // to be set to the Look and Feel of the native system.
  227.             /*
  228.             try {
  229.                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  230.             } 
  231.             catch (Exception e) { 
  232.             }
  233.             */
  234.  
  235.             //Create a new instance of our application's frame, and make it visible.
  236.             (new JFrame1()).setVisible(true);
  237.         } 
  238.         catch (Throwable t) {
  239.             t.printStackTrace();
  240.             //Ensure the application exits with an error condition.
  241.             System.exit(1);
  242.         }
  243.     }
  244.  
  245.     /**
  246.      * Notifies this component that it has been added to a container
  247.      * This method should be called by <code>Container.add</code>, and 
  248.      * not by user code directly.
  249.      * Overridden here to adjust the size of the frame if needed.
  250.      * @see java.awt.Container#removeNotify
  251.      */
  252.     public void addNotify()
  253.     {
  254.         // Record the size of the window prior to calling parents addNotify.
  255.         Dimension size = getSize();
  256.         
  257.         super.addNotify();
  258.         
  259.         if (frameSizeAdjusted)
  260.             return;
  261.         frameSizeAdjusted = true;
  262.         
  263.         // Adjust size of frame according to the insets and menu bar
  264.         com.sun.java.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
  265.         int menuBarHeight = 0;
  266.         if (menuBar != null)
  267.             menuBarHeight = menuBar.getPreferredSize().height;
  268.         Insets insets = getInsets();
  269.         setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight);
  270.     }
  271.  
  272.     // Used by addNotify
  273.     boolean frameSizeAdjusted = false;
  274.  
  275.     //{{DECLARE_CONTROLS
  276.     com.symantec.itools.swing.icons.ImageIcon newIcon = new com.symantec.itools.swing.icons.ImageIcon();
  277.     com.symantec.itools.swing.icons.ImageIcon openIcon = new com.symantec.itools.swing.icons.ImageIcon();
  278.     com.symantec.itools.swing.icons.ImageIcon saveIcon = new com.symantec.itools.swing.icons.ImageIcon();
  279.     com.symantec.itools.swing.icons.ImageIcon cutIcon = new com.symantec.itools.swing.icons.ImageIcon();
  280.     com.symantec.itools.swing.icons.ImageIcon copyIcon = new com.symantec.itools.swing.icons.ImageIcon();
  281.     com.symantec.itools.swing.icons.ImageIcon pasteIcon = new com.symantec.itools.swing.icons.ImageIcon();
  282.     com.symantec.itools.swing.icons.ImageIcon aboutIcon = new com.symantec.itools.swing.icons.ImageIcon();
  283.     java.awt.FileDialog saveFileDialog = new java.awt.FileDialog(this);
  284.     java.awt.FileDialog openFileDialog = new java.awt.FileDialog(this);
  285.     com.sun.java.swing.JPanel JPanel2 = new com.sun.java.swing.JPanel();
  286.     com.sun.java.swing.JToolBar JToolBar1 = new com.sun.java.swing.JToolBar();
  287.     com.sun.java.swing.JButton newButton = new com.sun.java.swing.JButton();
  288.     com.sun.java.swing.JButton openButton = new com.sun.java.swing.JButton();
  289.     com.sun.java.swing.JButton saveButton = new com.sun.java.swing.JButton();
  290.     com.symantec.itools.swing.JToolBarSeparator JToolBarSeparator1 = new com.symantec.itools.swing.JToolBarSeparator();
  291.     com.sun.java.swing.JButton cutButton = new com.sun.java.swing.JButton();
  292.     com.sun.java.swing.JButton copyButton = new com.sun.java.swing.JButton();
  293.     com.sun.java.swing.JButton pasteButton = new com.sun.java.swing.JButton();
  294.     com.symantec.itools.swing.JToolBarSeparator JToolBarSeparator2 = new com.symantec.itools.swing.JToolBarSeparator();
  295.     com.sun.java.swing.JButton aboutButton = new com.sun.java.swing.JButton();
  296.     com.sun.java.swing.JPanel JPanel1 = new com.sun.java.swing.JPanel();
  297.     com.sun.java.swing.JMenuBar JMenuBar1 = new com.sun.java.swing.JMenuBar();
  298.     com.sun.java.swing.JMenu fileMenu = new com.sun.java.swing.JMenu();
  299.     com.sun.java.swing.JMenuItem newItem = new com.sun.java.swing.JMenuItem();
  300.     com.sun.java.swing.JMenuItem openItem = new com.sun.java.swing.JMenuItem();
  301.     com.sun.java.swing.JMenuItem saveItem = new com.sun.java.swing.JMenuItem();
  302.     com.sun.java.swing.JMenuItem saveAsItem = new com.sun.java.swing.JMenuItem();
  303.     com.sun.java.swing.JSeparator JSeparator1 = new com.sun.java.swing.JSeparator();
  304.     com.sun.java.swing.JMenuItem exitItem = new com.sun.java.swing.JMenuItem();
  305.     com.sun.java.swing.JMenu editMenu = new com.sun.java.swing.JMenu();
  306.     com.sun.java.swing.JMenuItem cutItem = new com.sun.java.swing.JMenuItem();
  307.     com.sun.java.swing.JMenuItem copyItem = new com.sun.java.swing.JMenuItem();
  308.     com.sun.java.swing.JMenuItem pasteItem = new com.sun.java.swing.JMenuItem();
  309.     com.sun.java.swing.JMenu helpMenu = new com.sun.java.swing.JMenu();
  310.     com.sun.java.swing.JMenuItem aboutItem = new com.sun.java.swing.JMenuItem();
  311.     //}}
  312.  
  313.     //{{DECLARE_MENUS
  314.     //}}
  315.  
  316.     void exitApplication()
  317.     {
  318.         try {
  319.             // Beep
  320.             Toolkit.getDefaultToolkit().beep();
  321.             // Show a confirmation dialog
  322.             int reply = JOptionPane.showConfirmDialog(this, 
  323.                                                       "Do you really want to exit?", 
  324.                                                       "JFC Application - Exit" , 
  325.                                                       JOptionPane.YES_NO_OPTION, 
  326.                                                       JOptionPane.QUESTION_MESSAGE);
  327.             // If the confirmation was affirmative, handle exiting.
  328.             if (reply == JOptionPane.YES_OPTION)
  329.             {
  330.                 this.setVisible(false);    // hide the Frame
  331.                 this.dispose();            // free the system resources
  332.                 System.exit(0);            // close the application
  333.             }
  334.         } catch (Exception e) {
  335.         }
  336.     }
  337.  
  338.     class SymWindow extends java.awt.event.WindowAdapter
  339.     {
  340.         public void windowClosing(java.awt.event.WindowEvent event)
  341.         {
  342.             Object object = event.getSource();
  343.             if (object == JFrame1.this)
  344.                 JFrame1_windowClosing(event);
  345.         }
  346.     }
  347.  
  348.     void JFrame1_windowClosing(java.awt.event.WindowEvent event)
  349.     {
  350.         // to do: code goes here.
  351.              
  352.         JFrame1_windowClosing_Interaction1(event);
  353.     }
  354.  
  355.     void JFrame1_windowClosing_Interaction1(java.awt.event.WindowEvent event) {
  356.         try {
  357.             this.exitApplication();
  358.         } catch (Exception e) {
  359.         }
  360.     }
  361.  
  362.     class SymAction implements java.awt.event.ActionListener
  363.     {
  364.         public void actionPerformed(java.awt.event.ActionEvent event)
  365.         {
  366.             Object object = event.getSource();
  367.             if (object == openItem)
  368.                 openItem_actionPerformed(event);
  369.             else if (object == saveItem)
  370.                 saveItem_actionPerformed(event);
  371.             else if (object == exitItem)
  372.                 exitItem_actionPerformed(event);
  373.             else if (object == aboutItem)
  374.                 aboutItem_actionPerformed(event);
  375.             else if (object == openButton)
  376.                 openButton_actionPerformed(event);
  377.             else if (object == saveButton)
  378.                 saveButton_actionPerformed(event);
  379.             else if (object == aboutButton)
  380.                 aboutButton_actionPerformed(event);
  381.         }
  382.     }
  383.  
  384.     void openItem_actionPerformed(java.awt.event.ActionEvent event)
  385.     {
  386.         // to do: code goes here.
  387.              
  388.         openItem_actionPerformed_Interaction1(event);
  389.     }
  390.  
  391.     void openItem_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  392.         try {
  393.             // openFileDialog Show the FileDialog
  394.             openFileDialog.setVisible(true);
  395.         } catch (Exception e) {
  396.         }
  397.     }
  398.  
  399.     void saveItem_actionPerformed(java.awt.event.ActionEvent event)
  400.     {
  401.         // to do: code goes here.
  402.              
  403.         saveItem_actionPerformed_Interaction1(event);
  404.     }
  405.  
  406.     void saveItem_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  407.         try {
  408.             // saveFileDialog Show the FileDialog
  409.             saveFileDialog.setVisible(true);
  410.         } catch (Exception e) {
  411.         }
  412.     }
  413.  
  414.     void exitItem_actionPerformed(java.awt.event.ActionEvent event)
  415.     {
  416.         // to do: code goes here.
  417.              
  418.         exitItem_actionPerformed_Interaction1(event);
  419.     }
  420.  
  421.     void exitItem_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  422.         try {
  423.             this.exitApplication();
  424.         } catch (Exception e) {
  425.         }
  426.     }
  427.  
  428.     void aboutItem_actionPerformed(java.awt.event.ActionEvent event)
  429.     {
  430.         // to do: code goes here.
  431.              
  432.         aboutItem_actionPerformed_Interaction1(event);
  433.     }
  434.  
  435.     void aboutItem_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  436.         try {
  437.             // JAboutDialog Create with owner and show as modal
  438.             {
  439.                 JAboutDialog JAboutDialog1 = new JAboutDialog(this);
  440.                 JAboutDialog1.setModal(true);
  441.                 JAboutDialog1.show();
  442.             }
  443.         } catch (Exception e) {
  444.         }
  445.     }
  446.  
  447.     void openButton_actionPerformed(java.awt.event.ActionEvent event)
  448.     {
  449.         // to do: code goes here.
  450.              
  451.         openButton_actionPerformed_Interaction1(event);
  452.     }
  453.  
  454.     void openButton_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  455.         try {
  456.             // openFileDialog Show the FileDialog
  457.             openFileDialog.setVisible(true);
  458.         } catch (Exception e) {
  459.         }
  460.     }
  461.  
  462.     void saveButton_actionPerformed(java.awt.event.ActionEvent event)
  463.     {
  464.         // to do: code goes here.
  465.              
  466.         saveButton_actionPerformed_Interaction1(event);
  467.     }
  468.  
  469.     void saveButton_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  470.         try {
  471.             // saveFileDialog Show the FileDialog
  472.             saveFileDialog.setVisible(true);
  473.         } catch (Exception e) {
  474.         }
  475.     }
  476.  
  477.     void aboutButton_actionPerformed(java.awt.event.ActionEvent event)
  478.     {
  479.         // to do: code goes here.
  480.              
  481.         aboutButton_actionPerformed_Interaction1(event);
  482.     }
  483.  
  484.     void aboutButton_actionPerformed_Interaction1(java.awt.event.ActionEvent event) {
  485.         try {
  486.             // JAboutDialog Create with owner and show as modal
  487.             {
  488.                 JAboutDialog JAboutDialog1 = new JAboutDialog(this);
  489.                 JAboutDialog1.setModal(true);
  490.                 JAboutDialog1.show();
  491.             }
  492.         } catch (Exception e) {
  493.         }
  494.     }
  495. }
  496.